﻿jQuery.download = function (url, method) {
    var data, getUrlVars;

    getUrlVars = function (url) {
        var vars = [], hash;
        var hashes = url.slice(url.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push([hash[0], hash[1]])
        }
        return vars;
    };

    //url and data options required
    if (url) {
        //split params into form inputs
        var inputs, vars;
        vars = getUrlVars(url);

        jQuery.each(vars, function (key, pair) {
            inputs += '<input type="hidden" name="' + pair[0] + '" value="' + pair[1] + '" />';
        });

        //send request
        jQuery('<form action="' + url + '" method="' + (method || 'post') + '">' + inputs + '</form>')
		.appendTo('body').submit().remove();
    };
};